package com.bjsxt.service.impl;

import com.bjsxt.mapper.HostMapper;
import com.bjsxt.mapper.HostPowerMapper;
import com.bjsxt.pojo.Host;
import com.bjsxt.pojo.PageA;
import com.bjsxt.service.HostService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional  //事务管控
public class HostServiceImpl implements HostService {
    @Autowired
    private HostMapper hostMapper;
    @Autowired
    private HostPowerMapper hostPowerMapper;
    //主持人的条件查询
    @Override
    public PageA<Host> finfMore(Integer page,Integer rows,Host host) {
        Page pg = PageHelper.startPage(page, rows);
        List<Host> list = hostMapper.selectMore(host);
        PageA<Host> ppg=new PageA<>(list,pg.getTotal());
        return ppg;
    }
  //主持人当前权重的修改
    @Override
    public Integer updateHostSrong(Integer hid,String strong) {
        return  hostMapper.updateHostSrong(hid,strong);
    }
    //添加主持人
    @Override
/*    @Transactional  //事务管控*/
    public Integer saveHost(Host host) {
            //添加主持人的信息
            Integer insert = hostMapper.insert(host);
            //获得主持人的hid,hid为主持人表中的主键
            Integer insert1 = hostPowerMapper.insert(host.getHid());
             if (insert>0&&insert1>0){
                 return  1;
             }
        return 0 ;
    }
   //修改主持人的状态
    @Override
    public Integer updateHostStatus(Integer []hids, String status) {
       int a=0;
        try {
            for(Integer hid:hids){
                hostMapper.updateHostStatus(hid,status);
            }
            a=1;
        } catch (Exception e) {
            /*添加事件之后要把异常抛出,不能进行捕获*/
            throw e;
        }
       return a;
    }
}
